package com.database.bean;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name="SUPPLIER")
@AttributeOverride( name="id", column = @Column(name="id") )
@XmlRootElement
public class Supplier extends BaseBean{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Size(min=1, max=50)
	@Column(name="supplierName")
	private String supplierName=null;
	
	@Column(name="discountPerTenUnits")
	private Double discountPerTenUnits=null;  //amount,discount --> should be setted in Mask Manually or by default for predefined suppliers
	
	@Column(name="deliveryCost")
	private Double deliveryCost=null;
	
	@ManyToMany(fetch = FetchType.LAZY,mappedBy = "suppliers", cascade={CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH})
	private Set<Game> games = new HashSet<Game>(0);
	
	@OneToMany(fetch = FetchType.EAGER, cascade={CascadeType.ALL})
	@Fetch(value = FetchMode.JOIN)
    @JoinColumn(name="supplierId")
	private List<Product>products =new ArrayList<Product>();
	
	@Column(name="active", columnDefinition = "BIT", length = 1)
	private boolean active;
	
	public Supplier(){}

	public String getSupplierName() {
		return supplierName;
	}

	public void setSupplierName(String supplierName) {
		this.supplierName = supplierName;
	}

	public Double getDiscountPerTenUnits() {
		return discountPerTenUnits;
	}

	public void setDiscountPerTenUnits(Double discountPerTenUnits) {
		this.discountPerTenUnits = discountPerTenUnits;
	}

	public Double getDeliveryCost() {
		return deliveryCost;
	}

	public void setDeliveryCost(Double deliveryCost) {
		this.deliveryCost = deliveryCost;
	}

	@Override
	public String toString() {
		return "Supplier [supplierName=" + supplierName
				+ ", discountPerTenUnits=" + discountPerTenUnits
				+ ", deliveryCost=" + deliveryCost + ", games=" + games
				+ ", products=" + products + "]";
	}

	/**
	 * @return the games
	 */
	public Set<Game> getGames() {
		return games;
	}

	/**
	 * @param games the games to set
	 */
	public void setGames(Set<Game> games) {
		this.games = games;
	}

	public List<Product> getProducts() {
		return products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
	
	
}
